/*
 * Copyright [vega-ai-sdk] [rightbrain.art]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * According to vega feature, we modify some class，comment, field name, etc.
 */


package com.rightbrain.vegaai.tool.sdk.common;

import lombok.*;

import java.io.Serializable;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Resource<C, T> implements Serializable {
    private static final long serialVersionUID = 4072234795470508982L;
    private C code;
    private String message;
    private T data;
    private Integer total;

    public static <C, T> Resource<C, T> resource (C code, String message, T data) {
        return Resource.<C, T>builder().code(code).data(data).message(message).build();
    }

    public static <C, T> Resource<C, T> OK (C code, T data) {
        return resource(code, ResourceCode.OK.message(), data);
    }

    public static <T> Resource<String, T> OK (T data) {
        return resource(ResourceCode.OK.code(), ResourceCode.OK.message(), data);
    }

    public static <T> Resource<String, T> OK () {
        return resource(ResourceCode.OK.code(), ResourceCode.OK.message(), null);
    }

    public static <C, T> Resource<C, T> ERROR (C code, String message) {
        return resource(code, message, null);
    }

    public static <T> Resource<String, T> ERROR (String message) {
        return ERROR(ResourceCode.INTERNAL_SERVER_ERROR);
    }

    public static <T> Resource<String, T> ERROR (ResourceCode resourceCode) {
        return resource(resourceCode.code(), resourceCode.message(), null);
    }


}